<?php 

class ServerAction extends BaseAction{


	/**
	 * 首页
	 * @return [type] [description]
	 */
	function index(){
		$cid=intval($_GET['cid']);  //获取栏目ID
		if($cid==0){$cid=193;}
		$db=M("category");
		//$aboutinfo = M("category")->where($map)->order(array("orderid"=>"asc","id"=>"desc"))->find();
		if($r=$db->where(array("id"=>$cid,"checkinfo"=>0))->find()){
			$info=$r;
			if($info['seotitle']==''){
				$info['seotitle']=$info['classname'].'-'.C('cfg_webname');
			}
			if($info['keywords']==''){
				$info['keywords']=C('cfg_keyword');
			}
			if($info['description']==''){
				$info['description']=C('cfg_description');
			}
		}else{
			showMsg("参数错误");
			exit;
		}
		$map1['pid'] = 193;
		$map1['checkinfo'] =0;
		$class = M("category")->where($map1)->order(array("orderid"=>"asc","id"=>"desc"))->select();
		
		if($cid!=0){
			//产品列表开始
			$c=M('content');
			$maps['checkinfo']  = 0;
			if($cid!=193){
				$maps['pid'] = $cid;
			}else{
				$maps['path'] = array('like','0,193%');
			}
			$key=I('key');
			if($key!=""){
			//echo $key."+";
				$maps['title'] = array('like','%'.$key.'%');
				$this->assign("key",$key);
			}
			$count  = $c->where($maps)->count();// 查询满足要求的总记录数
			import('ORG.Util.Page');// 导入分页类
			$Page   = new Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show   = $Page->show();// 分页显示输出
			
			$list=$c
				->field('id,pid,title,style,picurl,posttime,url,htmlurl,description')
				->where($maps)
				->order('orderid asc,posttime desc,id desc')
				->limit($Page->firstRow.','.$Page->listRows)
				->select();
			foreach($list as $key=>$v){
					$list[$key]['style']=explode(';',$list[$key]['style']);
					$list[$key]['picurl']=formatUrl($list[$key]['picurl']);
					if($list[$key]['picurl']=="") $list[$key]['picurl']="__PUBLIC__/cn/images/nopic.jpg";
					
					if($list[$key]['url']==""){
						$list[$key]['link']=U('server/detail',array('id'=>$list[$key]['id']));
					}
					else{
						$list[$key]['link']=formatUrl($list[$key]['url']);
					}
					$list[$key]['href']="<a href=\"".$list[$key]['link']."\"  title=\"".$list[$key]['title']."\"  style=\"color:".$list[$key]['style'][0].";font-weight:".$list[$key]['style'][1].";\">".restrlen(escapeshow($list[$key]['title']),99,"...")."</a>";
				}
			//echo M('content')->getlastsql();
			$this->assign("list",$list);
			$this->assign('page',$show);// 赋值分页输出
		
		}
		
		$this->assign("class",$class);
		$this->assign("classlist",$class);
		$this->assign("info",$info);
		$this->assign("menucss6","on");
		$this->assign("searchpage",U('server/index'));
		$this->display();
		//header("location:".U("cn"));
	}
	function detail(){
		$id = I('id');
		//$id=intval($_GET['cid']);  //获取栏目ID
		//if($cid==0){$cid=53;}
		$db=M("content");
		//$aboutinfo = M("category")->where($map)->order(array("orderid"=>"asc","id"=>"desc"))->find();
		if($r=$db->where(array("id"=>$id,"checkinfo"=>0))->find()){
			$info=$r;
			//if($info['seotitle']==''){
			//	$info['seotitle']=$info['classname'].'-'.C('cfg_webname');
			//}
			$info['classname']=M("category")->where(array("id"=>$info['pid'],"checkinfo"=>0))->getField('classname');
			$data = json_decode($info['content_arr'], true);
			$info['model'] = $data['model'];
			$info['identify'] = $data['identify'];
			$info['down'] = $data['down'];
			//echo M("category")->getlastsql();
		//	print_r($info['classname']);
			$info['seotitle']=$info['title'];
			if($info['keywords']==''){
				$info['keywords']=C('cfg_keyword');
			}
			if($info['description']==''){
				$info['description']=C('cfg_description');
			}
			$db->where(array("id"=>$id,"checkinfo"=>0))->setInc('hits',1);
		}else{
			showMsg("参数错误");
			exit;
		}
		$map1['pid'] = 193;
		$map1['checkinfo'] =0;
		$class = M("category")->where($map1)->order(array("orderid"=>"asc","id"=>"desc"))->select();
		
		//上一篇  
		$front=$db->field("id,title")->where(array('id'=>array('gt',$id),"checkinfo"=>0,"pid"=>$info['pid']))->order('id asc')->limit('1')->find();  
	//	echo $c->getlastsql();
		$this->assign('front',$front);  
		//下一篇  
		$after=$db->field("id,title")->where(array('id'=>array('lt',$id),"checkinfo"=>0,"pid"=>$info['pid']))->order('id desc')->limit('1')->find();  
	//	echo $c->getlastsql();
		$this->assign('after',$after);
		
		$this->assign("class",$class);
		$this->assign("info",$info);
		$this->assign("menucss6","on");
		$this->assign("searchpage",U('server/index'));
		$this->display();
		//header("location:".U("cn"));
	}
	

}

?>